<template>
	<view>
		<!-- 搜索框 -->
		<view class="search_view">
			<u-search
				shape="square"
				:show-action="true" 
				action-text="搜索" 
				:clearabled="true"  
				:animation="true" 
				v-model="keywords"
				@search="search"
				@clear="clear">
			</u-search>
		</view>
		<view class="list" v-if="buffer"  >
			<view v-for="(item,index) in searchList" class="row" @click="goDetail(item.id)">
				<image :src="baseUrl + item.img" mode="widthFix"></image>
				<view class="info">
					<text>{{item.goodsname}}</text>	
					<text>￥{{item.price}}</text>	
					<text>3565评论</text>	 
				</view>
			</view>
		</view>
		<view class="api" v-else>
			没有数据亲！
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buffer:true,//页面显示开关,
				keywords:'',//初始化搜索关键词
				searchList:[],
				baseUrl:this.$baseUrl
			}
		},
		onLoad(options){
			console.log(options.keywords);
			this.keywords = options.keywords;
			
			this.search()
		},
	
		methods: {
			// 2.去详情页
			goDetail(id){
				console.log(id);
				uni.navigateTo({
					url:'../../packagePageA/pages/gooddesc/gooddesc?id=' + id
				})
			},
			// 1.搜索返回列表
			async search(){
				let res = await this.$http({
					url:'search?keywords=' + this.keywords
				})
				console.log(res);
				if(res.data.code === 200){
					console.log("商品搜索",res.data.list);
					if(res.data.list === null){
						this.buffer = false
					}else{
						this.buffer ?  '':this.buffer=true
						this.searchList = res.data.list
					}
				}
			},
			clear(){
				tihs.keywords = ''
			}
		},
		
	}
</script>

<style>
	/* 引入样式 */
	@import url("@/static/css/search.css");
</style>
